home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / examples / C / x03c.c < prev    next >
C/C++ Source or Header  |  1994-06-30  |  2KB  |  103 lines

  1. /* $Id: x03c.c,v 1.9 1994/06/30 17:57:13 mjl Exp $
  2.  * $Log: x03c.c,v $
  3.  * Revision 1.9  1994/06/30  17:57:13  mjl
  4.  * All C example programs: made another pass to eliminate warnings when using
  5.  * gcc -Wall.  Lots of cleaning up: got rid of includes of math.h or string.h
  6.  * (now included by plplot.h), eliminated redundant casts, put in more
  7.  * uniform comments, and other minor changes.
  8.  *
  9. */
  10.  
  11. /*    x03c.c
  12.  
  13.     Polar plot demo.
  14. */
  15.  
  16. #include <plplot.h>
  17.  
  18. #ifndef ROUND
  19. #define ROUND(a)    (PLINT)((a)<0. ? ((a)-.5) : ((a)+.5))
  20. #endif
  21.  
  22. /*----------------------------------------------------------------------*\
  23.  * main
  24.  *
  25.  * Generates polar plot, with 1-1 scaling.
  26. \*----------------------------------------------------------------------*/
  27.  
  28. int
  29. main(int argc, char *argv[])
  30. {
  31.     int i, j;
  32.     PLFLT dtr, theta, dx, dy, r;
  33.     char text[4];
  34.     static PLFLT x0[361], y0[361];
  35.     static PLFLT x[361], y[361];
  36.  
  37.     dtr = 3.141592654 / 180.0;
  38.     for (i = 0; i <= 360; i++) {
  39.     x0[i] = cos(dtr * i);
  40.     y0[i] = sin(dtr * i);
  41.     }
  42.  
  43. /* Parse and process command line arguments */
  44.  
  45.     (void) plParseInternalOpts(&argc, argv, PL_PARSE_FULL);
  46.  
  47. /* Initialize plplot */
  48.  
  49.     plinit();
  50.  
  51. /* Set up viewport and window, but do not draw box */
  52.  
  53.     plenv(-1.3, 1.3, -1.3, 1.3, 1, -2);
  54.     for (i = 1; i <= 10; i++) {
  55.     for (j = 0; j <= 360; j++) {
  56.         x[j] = 0.1 * i * x0[j];
  57.         y[j] = 0.1 * i * y0[j];
  58.     }
  59.  
  60. /* Draw circles for polar grid */
  61.  
  62.     plline(361, x, y);
  63.     }
  64.  
  65.     plcol(2);
  66.     for (i = 0; i <= 11; i++) {
  67.     theta = 30.0 * i;
  68.     dx = cos(dtr * theta);
  69.     dy = sin(dtr * theta);
  70.  
  71. /* Draw radial spokes for polar grid */
  72.  
  73.     pljoin(0.0, 0.0, dx, dy);
  74.     sprintf(text, "%d", ROUND(theta));
  75.  
  76. /* Write labels for angle */
  77.  
  78.     if (dx >= 0)
  79.         plptex(dx, dy, dx, dy, -0.15, text);
  80.     else {
  81.         plptex(dx, dy, -dx, -dy, 1.15, text);
  82.     }
  83.     }
  84.  
  85. /* Draw the graph */
  86.  
  87.     for (i = 0; i <= 360; i++) {
  88.     r = sin(dtr * (5 * i));
  89.     x[i] = x0[i] * r;
  90.     y[i] = y0[i] * r;
  91.     }
  92.     plcol(3);
  93.     plline(361, x, y);
  94.  
  95.     plcol(4);
  96.     plmtex("t", 2.0, 0.5, 0.5, "#frPLplot Example 3 - r(#gh)=sin 5#gh");
  97.  
  98. /* Close the plot at end */
  99.  
  100.     plend();
  101.     exit(0);
  102. }
  103.